
#include <Windows.h>

class CSLock
{
public:
	class AutoLock
	{
	public:
		AutoLock( CSLock &m )
			: m_cs( m )
		{
			m_cs.lock();
		}
		~AutoLock()
		{
			m_cs.unlock();
		}
	protected:
		CSLock &m_cs;
	};

	void lock()
	{
		EnterCriticalSection( &_cs );
	}
	void unlock()
	{
		LeaveCriticalSection( &_cs );
	}
	CSLock()
	{
		memset( &_cs, NULL, sizeof( _cs ) );
		InitializeCriticalSectionAndSpinCount( &_cs, 4000 );
	}
	~CSLock()
	{
		DeleteCriticalSection( &_cs );
	}
protected:
	CRITICAL_SECTION _cs;
};

